package com.whmall.service.crm.provider;

import com.whmall.component.entity.dto.PageReqDTO;
import com.whmall.component.entity.dto.PageRspDTO;
import com.whmall.service.crm.api.SupplierDevelopPoolApi;
import com.whmall.service.crm.entity.dto.supplierdevelop.*;
import com.whmall.service.crm.module.supplierdeveloppool.service.SupplierDevelopPoolFollowService;
import com.whmall.service.crm.module.supplierdeveloppool.service.SupplierDevelopPoolLogService;
import com.whmall.service.crm.module.supplierdeveloppool.service.SupplierDevelopPoolService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = SupplierDevelopPoolApi.class)
public class SupplierDevelopPoolProvider implements SupplierDevelopPoolApi {

    @Autowired
    private SupplierDevelopPoolService developPoolService;

    @Autowired
    private SupplierDevelopPoolLogService poolLogService;

    @Autowired
    private SupplierDevelopPoolFollowService poolFollowService;

    @Override
    public PageRspDTO<SupplierDevelopQueryRspDTO> list(PageReqDTO pageReqDTO, SupplierDevelopQueryRepDTO repDTO) {
        return developPoolService.list(pageReqDTO, repDTO);
    }

    @Override
    public void acquireSupplier(Long employeeId, Long companyId) {
        developPoolService.acquireSupplier(employeeId, companyId);
    }

    @Override
    public void releaseSupplier(ReleaseSupplierReqDTO reqDTO) {
        developPoolService.releaseSupplier(reqDTO);
    }

    @Override
    @Transactional
    public void acquireSupplier(List<AcquireSupplierReqDTO> reqDTOS) {
        reqDTOS.forEach(e -> {
            developPoolService.acquireSupplier(e.getEmployeeId(), e.getCompanyId());
        });
    }

    @Override
    @Transactional
    public void releaseSupplier(List<ReleaseSupplierReqDTO> reqDTOS) {
        reqDTOS.forEach(e -> {
            developPoolService.releaseSupplier(e);
        });
    }

    @Override
    public void addControlDirectory(AddControlDirectoryReqDTO reqDTO) {
        developPoolService.addControlDirectory(reqDTO);
    }

    @Override
    public void removeControlDirectory(Long employeeId, Long companyId) {
        if(!developPoolService.removeControlDirectory(employeeId, companyId)){
            throw new IllegalArgumentException("不满足移除条件 不能移除该控制目录");
        }
    }

    @Override
    public PageRspDTO<SupplierDevelopPoolLogQueryRspDTO> listLog(PageReqDTO pageReqDTO, Long companyId) {
        return poolLogService.list(pageReqDTO, companyId);
    }

    @Override
    public Long saveFollow(SupplierDevelopPoolFollowSaveReqDTO saveReqDTO) {
        return poolFollowService.saveFollow(saveReqDTO);
    }

    @Override
    public PageRspDTO<SupplierDevelopPoolFollowRspDTO> listFollow(PageReqDTO pageReqDTO, Long companyId) {
        return poolFollowService.list(pageReqDTO, companyId);
    }
}
